package com.mew.slots.util;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.mew.slots.core.common.handler.AbstractBetHandler;
import com.mew.slots.core.common.messge.response.SlotsPlayResponseMessage;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.kbwsj.message.KbwsjPlayResponseMessage;
import com.mew.slots.core.game.klxg.bo.KlxgInRoom;
import com.mew.slots.core.game.mnyys.dto.MnyysInRoom;
import com.mew.slots.core.game.szxz.dto.SzxzInRoom;
import com.mew.slots.core.game.zzdzz.dto.ZzdzzInRoomList;
import com.mew.slots.util.free.FreeUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author dylin
 * @create 2021/4/23
 */
public class Play {
    public static SlotsPlayResponseMessage szxzLockGold(StrategyGameVO player, AbstractBetHandler handler){
        if(player.getWinFree().getFrees()==0){
            player.getWinFree().setFrees(1);
            player.getWinFree().setFreeNumber(7);
            player.getWinFree().setFreeType(2);
            SzxzInRoom in=new SzxzInRoom();
            in.setRemoveIcon(computeRemoveIcon());
            player.getWinFree().setJson(JSON.toJSONString(in));
        }
        return handler.play(player,null);
    }
    public static SlotsPlayResponseMessage zzdzzFree(StrategyGameVO player, AbstractBetHandler handler){
        if(player.getWinFree().getFrees()==0){
            player.getWinFree().setFrees(1);
            player.getWinFree().setFreeNumber(5);
            ZzdzzInRoomList list=new ZzdzzInRoomList();
            list.setFreeCoins(new long[]{
                    FreeUtil.zzdzzComputeFreeCoin(player.getInBetNumber(),player.getLineNumber()),
                    FreeUtil.zzdzzComputeFreeCoin(player.getInBetNumber(),player.getLineNumber()),
                    FreeUtil.zzdzzComputeFreeCoin(player.getInBetNumber(),player.getLineNumber()),
                    FreeUtil.zzdzzComputeFreeCoin(player.getInBetNumber(),player.getLineNumber()),
                    FreeUtil.zzdzzComputeFreeCoin(player.getInBetNumber(),player.getLineNumber())
            });
            player.getWinFree().setJson(JSON.toJSONString(list));
        }
        return handler.play(player,null);
    }

    public static SlotsPlayResponseMessage klxgFree(StrategyGameVO player, AbstractBetHandler handler){
        if(player.getWinFree().getFrees()==0){
            player.getWinFree().setFrees(1);
            player.getWinFree().setFreeNumber(10);
            player.getWinFree().setJson(null);
        }
        return handler.play(player,null);
    }

    public static SlotsPlayResponseMessage mnyysLock(StrategyGameVO player, AbstractBetHandler handler){
        if(player.getWinFree().getFrees()==0){
            player.getWinFree().setFrees(1);
            player.getWinFree().setFreeNumber(10);
            MnyysInRoom in=new MnyysInRoom();
            List<Integer> gfs=in.getGoldenFrees();
            gfs.clear();
            gfs.add(RandomUtil.randomInt(0,3)*6);
            gfs.add(RandomUtil.randomInt(0,3)*6+5);
            player.getWinFree().setJson(JSON.toJSONString(in));
        }
        return handler.play(player,null);
    }

    private static List<Integer> computeRemoveIcon(){
        ArrayList<Integer> tempNum=new ArrayList<>();
        int dri= RandomUtil.randomInt(0,5);
        for (int i = 0; i < 5; i++) {
            if(dri!=i){
                tempNum.add(i);
            }
        }
        Collections.shuffle(tempNum);
        return tempNum;
    }

    public static void doOthers(String gameType,SlotsPlayResponseMessage res,List<Long> others){
        if ("kbwsj".equals(gameType)){
             kbwsj(res,others);
        }
        //return new long[0];
    }

    public static void kbwsj(SlotsPlayResponseMessage res,List<Long> others){
        if (others.size()==0){
            others.add(0l);
            others.add(0l);
            others.add(0l);
            others.add(0l);
        }
        others.set(0,others.get(0)+(((KbwsjPlayResponseMessage)res).getBouns()>0?1:0));
        others.set(1,others.get(1)+(((KbwsjPlayResponseMessage)res).getBounsGold()));
        others.set(2,others.get(2)+(((KbwsjPlayResponseMessage)res).getIsVampire()>0?1:0));
        others.set(3,others.get(3)+(((KbwsjPlayResponseMessage)res).getVampireWin()));

    }
}
